<template>
  <div class="admin">
    <el-container>
      <el-aside  :width="isTrue ? '64px' : '200px'">
        <div class="aside_head">
          <img src="../assets/img/header.png" alt="" />
          <p>{{ username }}<span>管理员</span></p>
        </div>
        <MenuLeft :isTrue="isTrue" />
      </el-aside>
      <el-container>
        <el-header>
          <i v-show="!isTrue" class="el-icon-s-fold" @click="changeClose"></i>
          <i
            v-show="isTrue"
            style="color: #79bbff"
            class="el-icon-s-unfold"
            @click="changeClose"
          ></i>
          <el-popconfirm
            title="你确定要退出吗？"
            confirm-button-text="Yes"
            cancel-button-text="No"
            @confirm="backlogin"
          >
            <el-button type="primary" slot="reference">退出</el-button>
          </el-popconfirm>
        </el-header>
        <el-main>
          <div class="main">
            <el-breadcrumb separator-class="el-icon-arrow-right">
              <el-breadcrumb-item separator="" v-show=" breadList.meta.title == '首页'">首页</el-breadcrumb-item>
              <el-breadcrumb-item v-show=" breadList.meta.title != '首页'" replace :to="{ path: '/admin/home' }">首页</el-breadcrumb-item>
              <el-breadcrumb-item v-show=" breadList.meta.title != '首页'">{{ breadList.meta.title }}</el-breadcrumb-item>
            </el-breadcrumb>
            <router-view />
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { mapState } from "vuex";
import { deleteToken } from "../utils/token";
import MenuLeft from "../components/MenuLeft.vue";
export default {
  name: "Admin",
  components: ["MenuLeft"],
  computed: {
    ...mapState(["username"]),
  },
  data() {
    return {
      isTrue: false,
      breadList: [], // 路由集合
    };
  },
  watch: {
    $route() {
      this.getBreadcrumb();
    },
  },
  methods: {
    backlogin() {
      deleteToken();
      this.$router.replace("/login");
    },
    changeClose() {
      this.isTrue = !this.isTrue;
    },
    isHome(route) {
      return route.name === "home";
    },
    getBreadcrumb() {
     
      //   console.log(matched)
      //如果不是首页
      /*   if (!this.isHome(matched[0])) {
          matched = [{ path: "/admin/home", meta: { title: "首页" } }].concat(matched);
        } */
     
      this.breadList = this.$route.matched[1]
    },
  },
  components: { MenuLeft },
  created() {
    this.getBreadcrumb();
  },
};
</script>

<style lang="less" scoped>
.admin {
  width: 100%;
  height: 100vh;
}
.el-breadcrumb {
  padding: 15px 0;
}
.el-header {
  background: #f1f1f1;
  --el-header-height: 50px;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
}
.el-header i {
  font-size: 25px;
  color: #b4b4b4;
}
.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
  background: #304156;
  transition: 0.5s;
}
.el-main {
  background-color: #fff;
  color: #333;
  text-align: left;
}
.main {
  background: #f1f1f1;
  min-height: 550px;
  border-radius: 10px;
  padding: 0 10px;
  box-sizing: border-box;
  padding-bottom: 20px;
}
/deep/.el-container {
  height: 100% !important;
}

.aside_head {
  margin-top: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  img {
    width: 60px;
    height: 60px;
    border-radius: 10px;
    vertical-align: middle;
  }
  p {
    color: #fff;
    font-size: 18px;
    line-height: 20px;
    margin: 10px 0 20px;
    span {
      margin-left: 5px;
    }
  }
}

/deep/ .el-button {
  width: 60px;
  height: 32px;
  padding: 8px 15px;
  box-sizing: border-box;
}
</style>